package com.goodmr.passport.webapp.Serivce.impl;

import com.goodmr.passport.account.PlatformModel;
import com.goodmr.passport.password.PasswordDao;
import com.goodmr.passport.webapp.Serivce.PasswordService;
import com.goodmr.passport.webapp.model.request.ChangePasswordReq;
import com.goodmr.passport.webapp.model.request.ResetPasswordReq;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 帐号密码重置服务
 *
 * @author <a href="mailto:bingdong13@msn.com">bigo</a>
 */
@Service("resetPasswordService")
public class ResetPasswordServiceImpl extends AccountServiceImpl implements PasswordService {

    @Autowired
    private PasswordDao passwordDao;

    /**
     * 帐号密码重置
     *
     * @param data 帐号密码信息
     */
    @Override
    public void modify(@NonNull ChangePasswordReq data) {

        ResetPasswordReq body = (ResetPasswordReq) data;

        validateAccount(body.getAccount());

        validatePassword(body.getPassword());

        validateCode(body.getAccount(), body.getCode());

        // 帐号信息
        PlatformModel platform = getByAccount(body.getAccount());

        // 修改密码
        passwordDao.modify(platform.getAccountId(), body.getPassword());
    }
}
